//引入路由
import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '@/pages/Home'
import About from '@/pages/About'
import History from '@/pages/History'
import Product from '@/pages/Product'
import News from '@/pages/News'
import Contact from '@/pages/Contact'
import NewsDetails from '@/pages/News/NewsDetails'
import NewsList from '@/pages/News/NewsList'
import ProductList from '@/pages/Product/ProductList'
import ProductDetails from '@/pages/Product/ProductDetails'
export default createRouter({

    history: createWebHashHistory(),//HTML模式——在路径中不会出现“#”，
    routes: [{
        name: "home",
        path: '/home',
        component: Home,
    },
    {
        name: "about",
        path: '/about',
        component: About
    },
    {
        name: "history",
        path: '/history',
        component: History
    },
    {
        name: "product",
        path: '/product',
        component: Product,
        children: [{
            path: "productlist",
            component: ProductList
        }, {
            name: "productdetails",
            path: "productdetails",
            component: ProductDetails
        },
        //重定向，项目跑起来时，访问/product，会定位到/product/productlist组件
        {
            path: '/product',
            redirect: "/product/productlist"
        }]
    },
    {
        name: "news",
        path: '/news',
        component: News,
        children: [{
            path: "newsdetails",
            component: NewsDetails
        },
        {
            path: "newslist",
            component: NewsList
        },
        //重定向，项目跑起来时，访问/news，会定位到/news/newslist组件
        {
            path: '/news',
            redirect: "/news/newslist"
        }
        ]
    },
    {
        name: "contact",
        path: '/contact',
        component: Contact
    },
    //重定向，项目跑起来时，访问/，会定位到home组件
    {
        path: '/',
        redirect: "/home"
    }
    ],
    //路由切换时自动滚动到顶部
    scrollBehavior() {
        return { top: 0 }
    },
})